﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Linq;
using System.Text;
using DomainDriver.DomainModeling.DomainObjects;
using DomainDriver.DomainModeling.StorageManagers.DataSetStorage;
using DomainDriver.DomainModeling.StorageManagers.EntityFrameworkStorage;
using ObjectRow = AutomotivePricingModel.AutomotivePricingDataSet.ProductionModelsRow;

namespace AutomotivePricingModel.ProductionModels
{
    public partial class ProductionModel : IEfEntity<Guid>, IDataSetSerializable<AutomotivePricingDataSet, DataRow>
    {
        #region ADO .NET Entities Framework Storage

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid EF_Id
        {
            get { return m_Key; }
            set { m_Key = value; }
        }

        #endregion

        #region AutomotivePricingDataSet Serialization

        string IDataSetSerializable<AutomotivePricingDataSet, DataRow>.ObjectTableName
        {
            get { return AutomotivePricingDataSet.SchemaHelper.ProductionModels.TableName; }
        }

        string IDataSetSerializable<AutomotivePricingDataSet, DataRow>.KeyColumnName
        {
            get { return AutomotivePricingDataSet.SchemaHelper.ProductionModels.EF_ProductionModelIdColumn.ColumnName; }
        }

        void IDataSetSerializable<AutomotivePricingDataSet, DataRow>.Serialize(AutomotivePricingDataSet datasource, DataRow dataRow)
        {
            ObjectRow objectRecord = dataRow as ObjectRow;

            objectRecord.EF_ProductionModelId = m_Key;
            dataRow.SerializeString(m_ModelName, datasource.ProductionModels.ModelNameColumn);
            objectRecord.SerializeNullableField<Guid>(m_ParentBrand, AutomotivePricingDataSet.SchemaHelper.ProductionModels.ParentBrandColumn);
        }

        void IDataSetSerializable<AutomotivePricingDataSet, DataRow>.Deserialize(AutomotivePricingDataSet datasource, DataRow dataRow)
        {
            ObjectRow objectRecord = dataRow as ObjectRow;

            m_Key = objectRecord.EF_ProductionModelId;
            dataRow.DeserializeString(out m_ModelName, datasource.ProductionModels.ModelNameColumn);
            objectRecord.DeserializeNullableField<Guid>(out m_ParentBrand, AutomotivePricingDataSet.SchemaHelper.ProductionModels.ParentBrandColumn);
        }

        #endregion
    }
}